import Vue from 'vue'
import App from './App.vue'
import router from './router'

//引入element库
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

// 引入axios库
import axios from 'axios'
Vue.prototype.$axios = axios
//默认地址
axios.defaults.baseURL = 'http://127.0.0.1:3000'


// 推送一个惊喜
router.beforeEach((to, from, next) => {
  // 1. 如果跳转的不是登录页, 要检查 token
  if (to.path != '/login') {
    if (localStorage.getItem('token')) {
      next()
    }else {
      router.push('login')
    }
  }else {
    next()
  }
})



Vue.config.productionTip = false

new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')

